/******************************************************************************
 *  _____     _____
 *  \  __\    \  __\
 *   \ \_\\    \ \_\\
 *    \  __\SS  \  __\roject
 *     \_\       \_\
 *
 * Mateusz Maciąg, Rafał Urbański
 * Komputerowe Systemy Sterowania
 *****************************************************************************/

#include "WrmnkTestControllerDesigner.h"
#include "ui_WrmnkTestControllerDesigner.h"

#include <QMessageBox>
#include <sstream>

using namespace std;
using namespace RafMat::SimInterface;

WrmnkTestControllerDesigner::WrmnkTestControllerDesigner(QWidget *parent) :
    ControllerDesigner(parent),
    ui(new Ui::WrmnkTestControllerDesigner)
{
    ui->setupUi(this);
}

WrmnkTestControllerDesigner::~WrmnkTestControllerDesigner()
{
    delete ui;
}

void WrmnkTestControllerDesigner::attachController(RafMat::SimInterface::IConfigurableSPtr ctrl)
{
    m_controllerConf = ctrl;

    try
    {
        ui->edADegree->setValue(QString::fromStdString(m_controllerConf->getParameter("da")).toDouble());
        ui->edBDegree->setValue(QString::fromStdString(m_controllerConf->getParameter("db")).toDouble());
        ui->edDelay->setValue(QString::fromStdString(m_controllerConf->getParameter("k")).toDouble());
        ui->edLambda->setValue(QString::fromStdString(m_controllerConf->getParameter("lambda")).toDouble());
   }
    catch(iconf_error& e)
    {
        QMessageBox::warning(this, "Error", e.what());
    }
}

void WrmnkTestControllerDesigner::applySettings()
{
    try
    {
        m_controllerConf->setParameter("da", ui->edADegree->text().toStdString());
        m_controllerConf->setParameter("db", ui->edBDegree->text().toStdString());
        m_controllerConf->setParameter("k", ui->edDelay->text().toStdString());
        m_controllerConf->setParameter("lambda", ui->edLambda->text().toStdString());
    }
    catch(iconf_error& e)
    {
        QMessageBox::warning(this, "Error", e.what());
    }

}




